/**
 * 
 */
package com.cp16.tss.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.cp16.tss.model.Device;

/**
 * @author ADMIN
 * 
 */
public class DeviceDAO {

	SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
	
	public Device getDeviceByName(String deviceName) throws Exception {
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		session.getTransaction().commit();
		session.close();
		Device device = (Device) session.get(Device.class, deviceName);
		return device;
	}

	public boolean addDevice(Device device) throws Exception {
		try {
			Session session = sessionFactory.openSession();
			session.beginTransaction();
			session.save(device);
			session.getTransaction().commit();
			session.close();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	public boolean updateDevice(Device device) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean deleteDevice(Device device) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

}
